//
//  ChatViewController.m
//  Main
//
//  Created by junFung on 15/7/27.
//  Copyright (c) 2015年 junFung. All rights reserved.
//

#import "JTextField.h"

@interface JTextField ()

@end

@implementation JTextField

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews
{
    UIToolbar *toolbar = [[UIToolbar alloc] init];
    toolbar.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:toolbar];
    self.toolbar = toolbar;
    
    
    UITextField *textfield = [[UITextField alloc] init];
    textfield.backgroundColor = [UIColor whiteColor];
    [toolbar addSubview:textfield];
    self.textfield = textfield;

    UIButton *sendButton = [[UIButton  alloc] init];
    [sendButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [sendButton setTitle:@"发送" forState:UIControlStateNormal];
    [sendButton addTarget:self action:@selector(sendbuttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [toolbar addSubview:sendButton];
    self.sendbutton = sendButton;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.toolbar.frame = CGRectMake(0, self.frame.size.height-self.toolbar.frame.size.height, self.frame.size.width, 44);
    self.textfield.frame = CGRectMake(10, 5, self.toolbar.frame.size.width-60, 34);
    self.sendbutton.frame = CGRectMake(self.toolbar.frame.size.width-44, 0, 44, 44);
}

- (void)sendbuttonClick:(UIButton *)sender
{
    if ([self.delegate respondsToSelector:@selector(JTextFieldSendbutton:)]) {
        [self.delegate JTextFieldSendbutton:sender];
    }
}

@end